package com.think.teaching.service.impl;

import java.util.List;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.think.common.utils.Common;
import com.think.teaching.mapper.CourseNoticeMapper;
import com.think.teaching.model.CourseNotice;

@Service
public class CourseNoticeServiceImpl extends BaseServiceImpl<CourseNoticeMapper, CourseNotice>{
	
	
	public CourseNotice AddNotice(CourseNotice notice) {
		notice.setCreatedBy(Common.GetCurrentAuthor().getUserId());
		return this.save(notice)?notice:null;
	}
	
	public Boolean UpdateNotice(CourseNotice notice) {
		return this.updateById(notice);
	}
	
	public Boolean DeleteNotice(Integer id) {
		UpdateWrapper<CourseNotice> queryWrapper = new UpdateWrapper<CourseNotice>();
		queryWrapper.eq("id", id);
		queryWrapper.set("delflag", 1);
		return update(queryWrapper);
	}
	
	public IPage<CourseNotice> GetNotices(Integer page,Integer count,Integer courseId){
		IPage<CourseNotice> iPage = new Page<CourseNotice>(page,count);
		QueryWrapper<CourseNotice> queryWrapper = new QueryWrapper<CourseNotice>();
		queryWrapper.eq("course_id", courseId).ne("delflag", 1);
		return this.page(iPage,queryWrapper);
	}

}
